package com.lz.sports.adapter

import com.lz.library.adapter.BindingAdapter
import com.lz.sports.BR
import com.lz.sports.R
import com.lz.sports.bean.DeviceInfo

//设备管理
class DeviceManagerAdapter : BindingAdapter<DeviceInfo>() {

    override fun getLayoutResId(viewType: Int): Int = R.layout.item_device_manager

    override fun getVariableId(viewType: Int): Int = BR.device

    fun update(deviceInfo: DeviceInfo) {
        for (i in data.indices) {//id排序? 可二分查找
            if (data[i].id == deviceInfo.id) {
                notifyItemChanged(i)
                break
            }
        }
    }

    fun delete(deviceInfo: DeviceInfo) {
        for (i in data.indices) {//id排序? 可二分查找
            if (data[i].id == deviceInfo.id) {
                removeItem(i, true)
                break
            }
        }
    }
}